package com.ruoyi.dl.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dl.domain.DlProblem;
import com.ruoyi.dl.service.IDlProblemService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题反馈Controller
 * 
 * @author ruoyi
 * @date 2020-12-28
 */
@Controller
@RequestMapping("/dl/problem")
public class DlProblemController extends BaseController
{
    private String prefix = "dl/problem";

    @Autowired
    private IDlProblemService dlProblemService;

    @RequiresPermissions("dl:problem:view")
    @GetMapping()
    public String problem()
    {
        return prefix + "/problem";
    }

    /**
     * 查询问题反馈列表
     */
    @RequiresPermissions("dl:problem:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlProblem dlProblem)
    {
        startPage();
        List<DlProblem> list = dlProblemService.newSelectDlProblemList(dlProblem);
        return getDataTable(list);
    }

    /**
     * 导出问题反馈列表
     */
    @RequiresPermissions("dl:problem:export")
    @Log(title = "问题反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlProblem dlProblem)
    {
        List<DlProblem> list = dlProblemService.selectDlProblemList(dlProblem);
        ExcelUtil<DlProblem> util = new ExcelUtil<DlProblem>(DlProblem.class);
        return util.exportExcel(list, "problem");
    }

    /**
     * 新增问题反馈
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存问题反馈
     */
    @RequiresPermissions("dl:problem:add")
    @Log(title = "问题反馈", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlProblem dlProblem)
    {
        return toAjax(dlProblemService.insertDlProblem(dlProblem));
    }

    /**
     * 修改问题反馈
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DlProblem dlProblem = dlProblemService.selectDlProblemById(id);
        mmap.put("dlProblem", dlProblem);
        return prefix + "/edit";
    }

    /**
     * 修改保存问题反馈
     */
    @RequiresPermissions("dl:problem:edit")
    @Log(title = "问题反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlProblem dlProblem)
    {
        return toAjax(dlProblemService.updateDlProblem(dlProblem));
    }

    /**
     * 删除问题反馈
     */
    @RequiresPermissions("dl:problem:remove")
    @Log(title = "问题反馈", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlProblemService.deleteDlProblemByIds(ids));
    }
}
